package cn.bandeqing.product.controller;

import cn.bandeqing.base.resp.Resp;
import cn.bandeqing.base.resp.Table;
import cn.bandeqing.finance.resp.LabelValue;
import cn.bandeqing.product.req.*;
import cn.bandeqing.product.resp.ProductInventoryRecordTable;
import cn.bandeqing.product.resp.ProductInventoryTable;
import cn.bandeqing.product.resp.ProductSpecificationTable;
import cn.bandeqing.product.resp.ProductTable;
import cn.bandeqing.product.rpc.IProductRpc;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/product")
@RestController
@Tag(name = "产品")
public class ProductController {

    @DubboReference
    private IProductRpc productRpc;

    @Operation(summary = "refreshAllProductInventory")
    @PostMapping("/refreshAllProductInventory")
    public Resp<Void> refreshAllProductInventory() {
        return productRpc.refreshAllProductInventory();
    }

    @Operation(summary = "select")
    @PostMapping("/select")
    public Resp<List<LabelValue>> select(@RequestBody @Valid ProductSelectReq req) {
        return productRpc.select(req);
    }

    @Operation(summary = "inventoryRecordTable")
    @PostMapping("/inventoryRecordTable")
    public Resp<Table<ProductInventoryRecordTable>> inventoryRecordTable(@RequestBody @Valid ProductInventoryRecordTableReq req) {
        return productRpc.inventoryRecordTable(req);
    }

    @Operation(summary = "productChanegInventory")
    @PostMapping("/productChanegInventory")
    public Resp<Void> productChanegInventory(@RequestBody @Valid ProductChangeInventoryReq req) {
        productRpc.productChanegInventory(req);
        return Resp.success();
    }

    @Operation(summary = "specificationSelect")
    @PostMapping("/specificationSelect")
    public Resp<List<LabelValue>> specificationSelect(@RequestBody @Valid ProductSpecificationReq req) {
        return productRpc.specificationSelect(req);
    }

    @Operation(summary = "productInventoryTable")
    @PostMapping("/productInventoryTable")
    public Resp<Table<ProductInventoryTable>> productInventoryTable(@RequestBody @Valid ProductInventoryTableReq req) {
        return productRpc.productInventoryTable(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/productInventorySaveOrUpdate")
    public Resp<Void> productInventorySaveOrUpdate(@RequestBody @Valid ProductInventorySaveOrUpdateReq req) {
        productRpc.productInventorySaveOrUpdate(req);
        return Resp.success();
    }

    @Operation(summary = "productSpecificationTable")
    @PostMapping("/productSpecificationTable")
    public Resp<Table<ProductSpecificationTable>> productSpecificationTable(@RequestBody @Valid ProductSpecificationTableReq req) {
        return productRpc.productSpecificationTable(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/productSpecificationSaveOrUpdate")
    public Resp<Void> productSpecificationSaveOrUpdate(@RequestBody @Valid ProductSpecificationSaveOrUpdateReq req) {
        productRpc.productSpecificationSaveOrUpdate(req);
        return Resp.success();
    }

    @Operation(summary = "表格")
    @PostMapping("/table")
    public Resp<Table<ProductTable>> table(@RequestBody @Valid ProductTableReq req) {
        return productRpc.table(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/saveOrUpdate")
    public Resp<Void> saveOrUpdate(@RequestBody @Valid ProductSaveOrUpdateReq req) {
        productRpc.saveOrUpdate(req);
        return Resp.success();
    }

}
